package department.fc.controller;

import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import department.fc.common.AttributeAndView;
import department.fc.common.Controller;
import department.fc.service.DepartmentService;

public class RemoveDepartmentController implements Controller{

	@Override
	public AttributeAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		int departmentNum = Integer.parseInt(request.getParameter("departmentNum"));
		
		DepartmentService service = DepartmentService.getInstance();
		
		AttributeAndView av = null;
		
		try {
			service.removeDepartmentByNum(departmentNum);
			av = new AttributeAndView(true, "/MyDepartmentManagerFC/controller?command=dlc");
		} catch (SQLException e) {
			e.printStackTrace();
			av = new AttributeAndView(false, "/WEB-INF/jsp/error.jsp", "error_message", e.getMessage());
		}
		
	return av;	
	}

}
